<?php
$text = '<td >
		http://www.leadformix.com/ef1/index.php?module=Campaign&amp;action=createCampaign <br />
												http://leadformix.com/ef1/index.php?module=Campaign&amp;action=createCampaign <br />
												http://leadformix.com/ef1/&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; http://leadformix.com/ef1/index.html<br />
												<br />
												&nbsp;</td>';

$text = htmlspecialchars_decode($text);
//echo $text;
//echo "\r\n------------------------\r\n";
//echo clickable_link($text);

$str = '&nbsp;&nbsp;foo&nbsp; o   startn&nbsp;&nbsp;&nbsp;';
echo $str . "\r\n";
$str = preg_replace('/(&nbsp;)*$/', ' ', $str);

echo $str . "\r\n";


function clickable_link($text)
	{
		# this functions deserves credit to the fine folks at phpbb.com
		$text = preg_replace('#(script|about|applet|activex|chrome):#is', "\\1:", $text);
		//echo $text;
		//echo "\r\n------------------------\r\n";
		// pad it with a space so we can match things at the start of the 1st line.
		$ret = ' ' . $text;
		// matches an "xxxx://yyyy" URL at the start of a line, or after a space.
		// xxxx can only be alpha characters.
		// yyyy is anything up to the first space, newline, comma, double quote or <
		//$ret = preg_replace("#(^|[\n ]|[\nbsp; ])((https?)://[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"\\2\">\\2</a>", $ret);
		
		$ret = preg_replace("#(^|[\n ]|[\nbsp; ][\t]*)(((https?://)|(www.))[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"\\2\">\\2</a>", $ret);
		//$ret = preg_replace("#(^|[\n ]|[\nbsp; ])(((https?:((//)|(\\\\)))|(www.))[\w\d:#%/;$()~_?\\-=\.&]*)i", "\\1<a href=\"\\2\">\\2</a>", $ret);
		$ret = substr($ret, 1);
		return $ret;
	}
		
?>